package guan.bean;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

import net.sf.autodao.PersistentEntity;

import org.springframework.util.AutoPopulatingList;
import org.springframework.util.AutoPopulatingList.ElementFactory;
import org.springframework.util.AutoPopulatingList.ElementInstantiationException;

@Entity
public class ResCodeType implements PersistentEntity<Long> {
	@Id
	@GeneratedValue
	private Long id;

	private String name;

	@Column(unique = true)
	private String code;// 编码，用来获取

	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "resCodeTypeId")
	private List<ResCode> resCodeList = new AutoPopulatingList<ResCode>(
			new ElementFactory<ResCode>() {
				@Override
				public ResCode createElement(final int index)
						throws ElementInstantiationException {
					ResCode code = new ResCode();
					code.setResCodeType(ResCodeType.this);
					return code;
				}
			});

	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "resCodeTypeId")
	private List<ResCodeTest> resCodeTestList = new AutoPopulatingList<ResCodeTest>(
			new ElementFactory<ResCodeTest>() {
				@Override
				public ResCodeTest createElement(final int index)
						throws ElementInstantiationException {
					return new ResCodeTest();
				}
			});

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Override
	public Long getPrimaryKey() {
		return this.getId();
	}

	public List<ResCode> getResCodeList() {
		return resCodeList;
	}

	public void setResCodeList(List<ResCode> resCodeList) {
		this.resCodeList = resCodeList;
	}

	public List<ResCodeTest> getResCodeTestList() {
		return resCodeTestList;
	}

	public void setResCodeTestList(List<ResCodeTest> resCodeTestList) {
		this.resCodeTestList = resCodeTestList;
	}

}
